/*     */ package com.cr.api.controller;
/*     */ 
/*     */ import com.cr.api.vo.ServiceVo;
/*     */ import com.cr.business.domain.CrService;
/*     */ import com.cr.business.domain.CrServiceApplicationRecord;
/*     */ import com.cr.business.domain.CrUser;
/*     */ import com.cr.business.service.ICrServiceApplicationRecordService;
/*     */ import com.cr.business.service.ICrServiceService;
/*     */ import com.cr.business.service.ICrUserService;
/*     */ import com.cr.common.core.controller.BaseController;
/*     */ import com.cr.common.core.domain.AjaxResult;
/*     */ import com.cr.common.utils.ConvertUtil;
/*     */ import com.cr.common.utils.MyStringUtils;
/*     */ import com.github.pagehelper.PageInfo;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Date;
/*     */ import java.util.List;
/*     */ import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import org.springframework.beans.factory.annotation.Autowired;
/*     */ import org.springframework.web.bind.annotation.*;
/*     */
/*     */
/*     */

/*     */
/*     */ @RestController
/*     */ @RequestMapping({"/api/service"})
          @Api(description = "金典子服务")
          @CrossOrigin
/*     */ public class ApiServiceController extends BaseController {
/*     */   @Autowired
/*     */   private ICrServiceService serviceService;
/*     */   
/*     */   @Autowired
/*     */   private ICrUserService userService;
/*     */   
/*     */   @Autowired
/*     */   private ICrServiceApplicationRecordService serviceApplicationRecordService;
/*     */   
          /**
           * 服务列表
           */
          @ApiOperation("服务列表")
          @PostMapping("/getServiceList")
          @ApiImplicitParams({
              @ApiImplicitParam(name = "userId", value = "用户id",required = true, dataType = "Long"),
              @ApiImplicitParam(name = "userType", value = "用户类型",required = true, dataType = "Integer"),
              @ApiImplicitParam(name = "status", value = "服务状态，0 待服务，1已完成", required = true, dataType = "Integer"),
          })
          @ResponseBody
          public AjaxResult getServiceList(@RequestBody ServiceVo param)
          {
              Long userId = param.getUserId();
              Integer userType = param.getUserType();
              Integer status = param.getStatus();
              List<ServiceVo> serviceVoList = new ArrayList<>();
              CrService service = new CrService();
              if(userType == 1 || userType == 2){
                  //律师和机构
                  service.setLawyerId(userId);
                  service.setServiceStatus(status);
                  startPage();
                  List<CrService> serviceList = serviceService.selectCrServiceList(service);
                  if(serviceList.size() > 0){
                      serviceVoList = ConvertUtil.convertList(serviceList, ServiceVo.class);
                      for(ServiceVo vo : serviceVoList){
                          CrUser user = userService.selectCrUserByUserId(vo.getUserId());
                          vo.setUserName(user.getUserName());
                      }
                  }
          
              } else if(userType == 0){
                  //个人
                  service.setUserId(userId);
                  service.setServiceStatus(status);
                  startPage();
                  List<CrService> serviceList = serviceService.selectCrServiceList(service);
                  if(serviceList.size() > 0){
                      serviceVoList = ConvertUtil.convertList(serviceList, ServiceVo.class);
                      for(ServiceVo vo : serviceVoList){
                          CrUser user = userService.selectCrUserByUserId(vo.getLawyerId());
                          vo.setLawyerName(user.getUserName());
                          CrServiceApplicationRecord crServiceApplicationRecord = serviceApplicationRecordService.selectCrServiceApplicationRecordByApplyId(vo.getApplyId());
                          vo.setAmount(crServiceApplicationRecord.getPayAmount());
                      }
                  }
              }
              return AjaxResult.success(new PageInfo<>(serviceVoList));
          }
/*     */   
/*     */   @PostMapping({"/answer"})
/*     */   @ResponseBody
/*     */   public AjaxResult answer(@RequestBody ServiceVo param) {
              String answerContent = param.getAnswerContent();
              Long userId = param.getUserId();
              Long serviceId = param.getServiceId();
/*  94 */     if (userId == null)
/*  95 */       return AjaxResult.error("用户id不能为空"); 
/*  97 */     if (serviceId == null)
/*  98 */       return AjaxResult.error("问题id不能为空"); 
/* 100 */     if (MyStringUtils.isEmpty(answerContent))
/* 101 */       return AjaxResult.error("回答内容不能为空"); 
/* 103 */     CrService service = this.serviceService.selectCrServiceByServiceId(serviceId);
/* 104 */     service.setAnswerContent(answerContent);
/* 105 */     service.setLawyerId(userId);
/* 106 */     service.setAnswerTime(new Date());
/* 107 */     service.setUpdateBy(userId.toString());
/* 108 */     service.setUpdateTime(new Date());
/* 109 */     int i = this.serviceService.updateCrService(service);
/* 110 */     return toAjax(i);
/*     */   }

            /**
             * 确认完成
             * @param userId
             * @param serviceId
             * @return
             */
            @ApiOperation("确认完成")
//            @ApiImplicitParams({
//                    @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "Long"),
//                    @ApiImplicitParam(name = "serviceId", value = "问题id", required = true, dataType = "Long"),
//            })
            @GetMapping("/finish")
            @ResponseBody
            public AjaxResult finish(ServiceVo param){
                Long userId = param.getUserId();
                Long serviceId = param.getServiceId();
                if(userId == null){
                    return AjaxResult.error("用户id不能为空");
                }
                if(serviceId == null){
                    return AjaxResult.error("问题id不能为空");
                }
                CrService service = serviceService.selectCrServiceByServiceId(serviceId);
                service.setServiceStatus(1);
                service.setUpdateBy(userId.toString());
                service.setUpdateTime(new Date());
                int i = serviceService.updateCrService(service);
                return toAjax(i);
            }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-api-4.7.0.jar!\com\cr\api\controller\ApiServiceController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */